let fullAction = async function () {
  let count = 0;
  try {
    let buttons = document.getElementsByClassName("woo-font--angleDown");
    let ffk = document.getElementsByClassName("woo-font--cross");
    if (buttons.length == 1 && ffk.length == 0) {
      console.err("未检测到需要删除的微博！！");
      return
    }
    let now = new Date();
    console.log("开始执行删除微博,当前时间" + now);
    while (buttons.length != 1 || ffk.length != 0) {

      let notNeedDeleted = false;
      while (!notNeedDeleted && (buttons.length > 1 || ffk.length > 0)) {
        notNeedDeleted = true;
        if (buttons[1].title == '更多') {
          buttons[1].click();
          await delay(1000);
          let popmenus = document.getElementsByClassName("woo-pop-wrap-main");
          let popitem = popmenus[popmenus.length - 1].children;
          for (let i = 0; i < popitem.length; i++) {
            if (popitem[i].textContent == '删除' || popitem[i].textContent == '取消快转') {
              popitem[i].click();
              notNeedDeleted = false;
              await delay(500);
              await delay(1000, clickConfirm);
              count++;
              break;
            }
          }
        }
        if (ffk.length > 0) {
          if (ffk[0].title == '负反馈') {
            ffk[0].click();
            await delay(500);
            let popmenus = document.getElementsByClassName("woo-pop-wrap-main");
            let popitem = popmenus[0].children;
            for (let i = 0; i < popitem.length; i++) {
              if (popitem[i].textContent == '取消快转') {
                popitem[i].click();
                notNeedDeleted = false;
                await delay(500);
                await delay(500, clickConfirm);
                count++;
                break;
              }
            }
          }
        }
      }
    }


    console.log(`已将所有微博清空，删除条数为 ${count}`);
  } catch (err) {
    console.error("删除脚本停止运行", err);
    console.log(`已删除微博的条数为 ${count}`);
  }
}

function clickConfirm() {
  let ctb = document.getElementsByClassName("woo-dialog-btn");
  let qr;
  for (let index = 0; index < ctb.length; index++) {
    if (ctb[index].textContent == '\n        确定\n      ') {
      qr = ctb[index]; break;
    }
  }
  qr.click();
}

function delay(ms, fun) {
  if (fun) { fun(); }
  return new Promise(resolve => {
    setTimeout(() =>
      resolve(), ms);
  })
}

fullAction();